Determining Pattern Positions
As with the model for dashes, the QuickDraw GX model for patterns provides only for the case where the pattern shape remains the same throughout the entire patterned shape. If you want to pattern a shape and have the pattern change throughout it, you must use theGXGetShapePatternPositions
function. This function returns an array of points that identify the location of each pattern shape on the patterned shape.As an example, the sample function in this section shows you how to alter the patterned rectangle from the previous section. The sample function in Listing 3-20 first creates the patterned rectangle shown in Figure 3-75 and then uses the
GXGetShapePatternPositions
function to find the position of each small square in that patterned rectangle. The sample function then creates a picture, adding small squares at the appropriate positions, but rotating each new square a small amount.Listing 3-20 Changing a pattern throughout a patterned shape
void CreateBizarrePattern(void) { gxShape aRectangleShape, smallRectangle, aPicture; static gxRectangle rectangleGeometry = {ff(50), ff(50), ff(250), ff(150)}; static gxRectangle smallRectGeometry = {ff(0), ff(0), ff(10), ff(10)}; gxPatternRecord thePatternRecord; gxPoint *patternPositions; int numberOfPatterns, count; aRectangleShape = GXNewRectangle(&rectangleGeometry); GXSetShapeFill(aRectangleShape, gxEvenOddFill); smallRectangle = GXNewRectangle(&smallRectGeometry); GXSetShapeFill(smallRectangle, gxEvenOddFill); thePatternRecord.attributes = gxPortAlignPattern; thePatternRecord.pattern = smallRectangle; thePatternRecord.u.x = ff(0); thePatternRecord.u.y = ff(20); thePatternRecord.v.x = ff(20); thePatternRecord.v.y = ff(0); GXSetShapePattern(aRectangleShape, &thePatternRecord); numberOfPatterns = GXGetShapePatternPositions(aRectangleShape, nil); patternPositions = (gxPoint *) NewPtr(numberOfPatterns * sizeof(gxPoint)); GXGetShapePatternPositions(aRectangleShape, patternPositions); GXDisposeShape(aRectangleShape); aPicture = GXNewShape(gxPictureType); GXSetShapeAttributes(aPicture, gxUniqueItemsShape); for (count = 0; count < numberOfPatterns; count++) { GXRotateShape(smallRectangle, ff(10), 0, 0); GXMoveShapeTo(smallRectangle, patternPositions[count].x, patternPositions[count].y); AddToShape(aPicture, smallRectangle); } GXDisposeShape(smallRectangle); DisposePtr((Ptr)patternPositions); GXDrawShape(aPicture); GXDisposeShape(aPicture); }This function calls theGXGetShapePatternPositions
function twice. The first time, it sendsnil
as the value of the pattern positions array, which indicates that theGXGetShapePatternPositions
function should not return an actual array of positions, but should return as the function result the total number of pattern positions. Once the sample function has this total, it allocates enough memory to hold the array of pattern positions, and then callsGXGetShapePatternPositions
again to determine the actual positions.The result of this sample function is shown in Figure 3-77.
Figure 3-77 Shape with changing pattern
Notice that, in this case, the list of positions returned by
GXGetShapePatternPositions
starts at the upper-left corner and
works down each column of the patterned shape. In general, the order of
the positions returned by theGXGetShapePatternPositions
function is not guaranteed by QuickDraw GX.This sample function uses some concepts from other parts of QuickDraw GX. For more information about
- rotating and moving shapes, see the chapter "Transform Objects" in Inside Macintosh: QuickDraw GX Objects.
- pictures and adding elements to them, see Chapter 6, "Picture Shapes," in this book.
Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help